home *** CD-ROM | disk | FTP | other *** search
/ Megarom / Megarom Macintosh CD Software (Quantum Leap)(1992).iso / COMPRESS / DeHQX-200 / Source / Main.p < prev    next >
Encoding:
Text File  |  1991-08-23  |  3.8 KB  |  171 lines  |  [TEXT/PJMM]

  1. program Main;
  2.  
  3. { This program was written by Peter Lewis, Aug 1991 in THINK Pascal 3.0.2 }
  4. { To compile it you will need the System 7 versions of the Interface files }
  5. { Set Project Type to Application APPL/PnLh, has bundle}
  6. { Set Run Options to Use Resource File DeHQX.rsrc}
  7. { Set the project to include -}
  8. {Interfaces:}
  9. {    FixMath.p}
  10. {    Types.p}
  11. {    OSUtils.p}
  12. {    Files.p}
  13. {    Dialogs.p}
  14. {    StandardFile.p}
  15. {    AppleTalk.p}
  16. {    Aliases.p}
  17. {    Notification.p}
  18. {    PPCToolBox.p}
  19. {    Processes.p}
  20. {    EPPC.p}
  21. {    AppleEvents.p}
  22. {    Folders.p}
  23. {    GestaltEqu.p}
  24. {    Traps.p}
  25. {    Ballons.p}
  26. {CRC Object module:}
  27. {    CalcCRC.a.o}
  28. {My Libraries:}
  29. {    MyTypes.unit}
  30. {    MyLists.unit}
  31. {    MyUtilities.unit}
  32. {    MyAppleEvents.unit}
  33. {    MyNotifier.unit}
  34. {    MySystem7.unit}
  35. {    MyMainLoop.unit}
  36. {    MyFileSystem.unit}
  37. {    MyStandardFile.unit}
  38. {    MyMenus.unit}
  39. {DeHQX Files:}
  40. {    AppGlobals.p}
  41. {    Preferences.p}
  42. {    DoMenus.p}
  43. {    SmallEvents.p}
  44. {    CRCs.p}
  45. {    HQXLists.p}
  46. {    Displays.p}
  47. {    ReadHQX.p}
  48. {    DisplayHQX.p}
  49. {    DeHQX.p}
  50. {    Main.p}
  51. { Then turn off the Debug switche }
  52.  
  53.     uses
  54.         MyMainLoop, DoMenus, Types, OSUtils, Files, MyMenus, MyUtilities, MyFileSystem, MyLists, {}
  55.         MyTypes, MyAppleEvents, MySystem7, AppGlobals, SmallEvents, HQXLists, ReadHQX, DeHQX,{}
  56.         Preferences, MyNotifier;
  57.  
  58.     var
  59.         launched_with_option: boolean;
  60.  
  61.     function DoOApp: OSErr;
  62.     begin
  63.         if prefs.drop_folder and not launched_with_option then begin
  64.             AddFolder(prefs.drop_vrn, prefs.drop_dirID);
  65.         end;
  66.         if prefs.startup_state and in_foreground and not AnyInputFiles then
  67.          { Messy if we have got into the background already! So I just avoid it :-) }
  68.             DeHQXFiles;
  69.         DoOApp := noErr;
  70.     end;
  71.  
  72.     function DoODoc (fs: FSSpec): OSErr;
  73.         var
  74.             pb: CInfoPBRec;
  75.             oe: OSErr;
  76.     begin
  77.         with pb do begin
  78.             ioNamePtr := @fs.name;
  79.             ioVRefNum := fs.vRefNum;
  80.             ioDirID := fs.parID;
  81.             ioFDirIndex := 0;
  82.         end;
  83.         oe := PBGetCatInfo(@pb, false);
  84.         if oe = noErr then begin
  85.             if BAND(pb.ioFlAttrib, $0010) = 0 then
  86.                 AddFile(fs.vRefNum, fs.parID, fs.name, prefs.create_dir_state = CDS_Always, pb.ioFlLgLen)
  87.             else
  88.                 AddFolder(fs.vRefNum, pb.ioDirID);
  89.         end;
  90.         DoODoc := oe;
  91.     end;
  92.  
  93.     function DoQuit: OSErr;
  94.     begin
  95.         quitNow := true;
  96.         DoQuit := noErr;
  97.     end;
  98.  
  99.     var
  100.         er: eventRecord;
  101.         reply: HEreply;
  102.         s: str255;
  103.         sh: stringHandle;
  104.         paramCount, paramMessage, i: integer;
  105.         af: appFile;
  106.         doparams: boolean;
  107.         oe: OSErr;
  108.         dummyb: boolean;
  109. begin
  110.     dummyb := GetOSEvent(0, er);
  111.     launched_with_option := BAND(er.modifiers, optionKey) <> 0;
  112.     InitNotify;
  113.     InitUtilities;
  114.     if not has_AppleEvents then begin
  115.         CountAppFiles(paramMessage, paramCount);
  116.         if paramMessage <> appOpen then { Must be Open, not Print! }
  117.             begin
  118.             SysBeep(10);
  119.             halt;
  120.         end;
  121.     end;
  122.     InitReadHQX;
  123.     InitPreferences;
  124.     doparams := false;
  125.     if not has_AppleEvents then
  126.         for i := 1 to paramCount do begin
  127.             GetAppFiles(i, af);
  128.             with af do
  129.                 if fType = myAppType then begin
  130.                     GetPreferences(vRefNum, 0, fName);
  131.                     ClrAppFiles(i);
  132.                 end
  133.                 else
  134.                     doparams := true;
  135.         end;
  136.     InitMainLoop;
  137.     InitMenus(@DeHQXFiles);
  138.     InitCursor;
  139.  
  140.     SetMenus;
  141.  
  142.     if not has_AppleEvents and prefs.drop_folder and not launched_with_option then begin
  143.         AddFolder(prefs.drop_vrn, prefs.drop_dirID);
  144.     end;
  145.  
  146.     if has_AppleEvents then
  147.         oe := InitAppleEvents(@DoOApp, @DoODoc, nil, @DoQuit)
  148.     else begin
  149.         if doparams then begin
  150.             DeHQXParameters;
  151.         end { don't Auto DeHQX… or Drop Folder if any documents are double-clicked }
  152.         else if prefs.startup_state then begin
  153.             if prefs.drop_folder and not launched_with_option then begin
  154.                 AddFolder(prefs.drop_vrn, prefs.drop_dirID);
  155.             end;
  156.             if not AnyInputFiles then  { Don't Auto DeHQX… if Drop Folder }
  157.                 DeHQXFiles;
  158.         end;
  159.     end;
  160.     while not quitNow do begin
  161.         DeHQXList; { DeHQX any files that nead dehqxing }
  162.         if not quitNow then
  163.             HandleMainEvents(maxlongInt, nil, reply);
  164.         if quitNow then
  165.             quitNow := not FinishPreferences;
  166.     end;
  167.  
  168.     FinishMainLoop;
  169.     FinishReadHQX;
  170.     FinishNotify;
  171. end.